home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form Form1
- Caption = "Menu Array Example VB4 32"
- ClientHeight = 2610
- ClientLeft = 2685
- ClientTop = 3210
- ClientWidth = 5460
- Height = 3300
- Left = 2625
- LinkTopic = "Form1"
- LockControls = -1 'True
- ScaleHeight = 2610
- ScaleWidth = 5460
- Top = 2580
- Width = 5580
- Begin RichtextLib.RichTextBox RichTextBox1
- Height = 2625
- Left = 0
- TabIndex = 0
- Top = 0
- Width = 5445
- _Version = 65536
- _ExtentX = 9604
- _ExtentY = 4630
- _StockProps = 69
- BackColor = -2147483643
- ScrollBars = 3
- TextRTF = $"menus.frx":0000
- End
- Begin VB.Menu FileMenuHeader
- Caption = "&File"
- Begin VB.Menu FileMenuItem
- Caption = "&Open"
- Index = 1
- End
- Begin VB.Menu FileMenuItem
- Caption = "&Save"
- Enabled = 0 'False
- Index = 2
- End
- Begin VB.Menu FileMenuItem
- Caption = "-"
- Index = 3
- End
- Begin VB.Menu FileMenuItem
- Caption = "E&xit"
- Index = 4
- End
- End
- Attribute VB_Name = "Form1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub FileMenuItem_Click(Index As Integer)
- Dim FileName As String
- 'Note: Create this file if it doesn't exist already, or
- 'change it to another existing text file on your system.
- 'This example only deals with menu arrays, not File
- 'Handling nor Error Trapping. If you run the program and
- 'the file doesn't exist, choosing "Open" on the File Menu
- 'will cause an error.
-
- 'Hint: You don't need to exit Visual Basic to create this file.
- 'Simply run the program, type something in the RichTextBox1
- 'Control and choose "Save" from the File Menu. Once something
- 'is typed in the RichTextBox1, the "Save" option will become
- 'enabled. This will create the file and make it possible to
- 'reopen it.
- 'See RichTextBox1|Change for the code on how to enable/disable
- 'the Menu Array options for the "Save" function.
- FileName = "c:\test.txt" '<----------------------
- '
- Select Case Index '
- Case Is = 1 'Open File in RichTextBox1... '
- RichTextBox1.LoadFile FileName, rtfText '----'
- Case Is = 2 'Save File in RichTextBox1... '
- RichTextBox1.SaveFile FileName, rtfText '----'
- Case Is = 3 'This is the separator bar...
- Case Is = 4 'Exit program...
- End
- End Select
- End Sub
- Private Sub Form_Resize()
- If Form1.WindowState <> 1 Then 'If Form1 isn't minimized...
- 'This code keeps the RichTextBox1 Control "maximized" as the
- 'size of the container Form1 is changed. If you stretch or
- 'shrink the size of Form1 without this code, the RichTextBox1
- 'will stay the same size, causing either an ugly looking program
- '(if you make Form1 bigger), or, hidden controls (if you make
- 'Form1 smaller).
- 'To get the numbers to use here, just look at the Height and
- 'Width Properties for both Form1 and RichTextBox1. Since we
- 'always want the RichTextBox1 to fill the form, each time
- 'Form1 gets RESIZED, we also change the size of RichTextBox1
- 'to match. The difference in Width is 135 twips and the
- 'difference in Height is 675 twips. Subtract the difference
- 'from Form1 and we get where we want RichTextBox1 to end up.
- 'There are 15 twips per pixel (for you graphics people).
- RichTextBox1.Width = Form1.Width - 135 'Resize to match...
- 'The next If|Then is a graphics Error Trap. It keeps the user
- 'from making Form1 so small that RichTextBox1.Top would be
- 'outside of Form1 and cause an error. To see what happens,
- 'comment out the If|Then and run the program. Grab the lower
- 'righthand corner of Form1 and shrink the entire form as small
- 'as possible. The error will bring you right back here. ------
- 'We don't need to limit the Width to a minimum number '
- 'of twips. Windows already limits the minimum Width of Forms '
- 'that have a Control Box (the title bar with min|max|close '
- 'buttons). The Startup Form in all Visual Basic programs '
- 'MUST have a Control Box. Since this is the Startup Form '
- '(actually the ONLY Form), we don't need to worry about it. '
- '
- If Form1.Height < 1200 Then '
- Form1.Height = 1200 '
- End If '
- '
- 'We could have just made the number 675, but this way, the '
- 'smallest the user can make Form1 will still allow text in '
- 'RichTextBox1 to be seen. Only a tiny bit, but some. '
- '
- RichTextBox1.Height = Form1.Height - 675 '<-----------------'
- End If
-
- End Sub
- Private Sub RichTextBox1_Change()
- 'This code gets executed each time the text in RichTextBox1 changes.
- 'It only check to see if there is anything there or not.
- 'Note: Carriage Returns (CR) and Line Feeds (LF) count as "something".
- If RichTextBox1.Text = "" Then 'There's nothing in RichTextBox1...
- FileMenuItem(2).Enabled = False 'Turn OFF the "Save" option...
- Else 'Otherwise...
- FileMenuItem(2).Enabled = True 'Turn ON the "Save" option...
- End If
- End Sub
-